<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>设备档案</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<style type="text/css">
		.left-label {
			width: 100px !important
		}
	</style>
	<link rel="stylesheet" href="${pageContext.request.contextPath }/assets/css/layui.css"  media="all">
	<link rel="stylesheet" href="${pageContext.request.contextPath }/assets/css/toastr.min.css"  media="all">
</head>
<body>
<div class="demoTable" style="padding:10px 0 0 15px">
	<div class="layui-inline">
		<%--
			<input class="layui-input" name="searchTime" id="searchTime" placeholder="请输入时间检索" style="display: inline; width: 45%">
		--%>
		<input class="layui-input" name="keyword" id="keyword" placeholder="请输入设备名称" autocomplete="off" style="display: inline; width: 100%">
	</div>
	<button class="layui-btn layui-btn-blue" style="margin: 0 0 0 10px" data-type="reload"><i class="layui-icon layui-icon-search">搜索</i></button>
</div>
<table class="layui-hide" id="tableList" lay-filter="tableList"></table>
<table class="layui-hide" id="tableList1" lay-filter="tableList1"></table>
<script type="text/html" id="toolbar">
	<div class="layui-btn-container">
		<button class="layui-btn layui-btn-blue" lay-event="add"><i class="layui-icon layui-icon-add-1">新增</i></button>
		<button class="layui-btn layui-btn-blue" lay-event="delete"><i class="layui-icon layui-icon-delete">批量删除</i></button>
	</div>
</script>

<script type="text/html" id="rowToolbar">
	<a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
	<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>

<script src="${pageContext.request.contextPath }/assets/layui.js" charset="utf-8"></script>
<script src="${pageContext.request.contextPath }/assets/layui.all.js" charset="utf-8"></script>
<script src="${pageContext.request.contextPath }/assets/js/jquery.min.js" charset="utf-8"></script>
<script src="${pageContext.request.contextPath }/assets/js/toastr.min.js" charset="utf-8"></script>

<script type="text/javascript">
    layui.use(['table','layer','upload','form','laydate'], function(){
        var table = layui.table;
        var layer = layui.layer;
        var laydate = layui.laydate;
        var form = layui.form;

        var $ = layui.jquery, active = {
            reload:function () {
                /*var searchTime = $("#searchTime").val();*/
                var keyword01 = $("#keyword").val();
                /*console.log(searchTime + ',' + keyword)*/
                table.reload('contenttable',{
                    method:'get',
                    where:{"keyword01":keyword01},
                    page: {
                        curr: 1
                    }
                });
            }
        }
        $('.layui-btn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
        //设备台帐信息
        table.render({
            elem: '#tableList'
            ,url:'${pageContext.request.contextPath }/deviceFile/queryDeviceFile.do'
            ,toolbar: '#toolbar'
            ,title: '设备台帐信息'
            ,id :'contenttable'
            ,limits:[10,20,30]
            ,height: 380
            ,cols: [[
                {type: 'checkbox', fixed: 'left'},
                {field:'', title:'序号', sort: true, type:'numbers', width: 60},
                {field:'deviceName', title:'设备名称'},
                {field:'deviceNo', title:'设备编号'},
                {field:'deviceVersion', title:'设备型号'},
                {field:'useLocation', title:'使用地点'},
                {field:'outTime', title:'出厂日期'},
                {field:'useTime', title:'使用日期'},
                {field:'manufacturers', title:'设备生产厂家'},
                {field:'op1', title:'附属设备明细', templet:function (rowData){
					return "<a href='javascript:void(0)' style='color:#4D61B3' onclick='attachDeviceEvent(\""+rowData.id+"\")'>"+'查看详细'+"</a>";
				}},
                {field:'op2', title:'检修', templet:function (rowData){
					return "<a href='javascript:void(0)' style='color:#4D61B3' onclick='overhaulEvent(\""+rowData.id+"\")'>"+'查看详细'+"</a>";
				}},
                {field:'op3', title:'易耗品', templet:function (rowData){
					return "<a href='javascript:void(0)' style='color:#4D61B3' onclick='lubricateEvent(\""+rowData.id+"\")'>"+'查看详细'+"</a>";
				}},
                {fixed: 'right',title:'操作', toolbar: '#rowToolbar', width: 120}
            ]],
            page: true
        });
        //设备维修申请表登记
        table.render({
            elem: '#tableList1'
            ,url:'${pageContext.request.contextPath }/maintResume/queryMaintenanceRecord.do'
            /* ,toolbar: '#toolbarDemo' */
            ,title: '设备维修申请表登记'
            /* ,id :'contenttable' */
            ,limits:[10,20,30]
            ,height: 380
            ,cols: [[
                {type: 'checkbox', fixed: 'left'}
                ,{field:'', title:'序号', sort: true, type:'numbers', width: 60}
                ,{field:'deviceName', title:'设备名称'}
                ,{field:'deviceNo', title:'设备编号'}
                ,{field:'deviceVersion', title:'设备型号'}
                ,{field:'maintainType', title:'保养类别'}
                ,{field:'maintainCycle', title:'保养周期'}
                ,{field:'maintainTime', title:'保养时间', templet: function(row){
					if(row.maintainTime == ''){
						return '';
					} else {
						return createTime(row.maintainTime);
					}
				}}
                ,{field:'maintainResult', title:'保养结果'}
                ,{field:'maintainRemark', title:'备注'}
                ,{field:'op1', title:'保养项目', templet:function (rowData){
                        return "<a href='javascript:void(0)' style='color:#4D61B3' onclick='maintenanceRecordDetailEvent(\""+rowData.id+"\")'>"+'查看详细'+"</a>";
                    }}
                /* ,{field: 'right', title:'操作', toolbar: '#rowToolbar', align: 'center'} */
            ]]
            ,page: true
        });

        //头工具栏事件
        table.on('toolbar(tableList)', function(obj){
            var checkStatus = table.checkStatus(obj.config.id);
            switch(obj.event){
                case 'add':
                    layer.open({
                        type: 1 					//Page层类型
                        ,area: ['750px', '450px'] 	//宽  高
                        ,title: '新增'
                        ,shade: 0.6 				//遮罩透明度
                        ,maxmin: true 				//允许全屏最小化
                        ,anim: 1 					//0-6的动画形式，-1不开启
                        ,content: '<form class="layui-form" id="addFormID">'+
									'<div style="border: 1px solid #E6E6E6; margin: 15px 15px;">'+
										'<table>'+
											'<tr>'+
												'<td><label class="layui-form-label" style="margin-left:-10px; margin-top:9px">设备编号</label></td>&nbsp;'+
												'<td>'+
													'<div style="">'+
														'<div style="width: 200px; margin-left: 25px; float: left">' +
															'<select class="layui-select" id="deviceNo" name="deviceNo" lay-filter="displayInfo" lay-verify="deviceNo">' +
																'<option value="">请选择</option>' +
															'</select>' +
														'</div>' +
														'<div style="margin-top: 9px; float: left">'+
															'<font style="color:red; font-size: 24px; margin-left: 4px">*</font>'+
														'</div>'+
													'</div>' +
												'</td>'+
												'<td><label class="layui-form-label" style="margin-left:20px; margin-top:9px">设备名称</label></td>'+
												'<td><input readonly class="layui-input" type="text" id="deviceName" name="deviceName" lay-verify="deviceName" style="width:200px; margin-top:-1px; margin-left:-2px; display: inline;">' +
                                                    '<div class="layui-inline" style="margin-top: 4px;">'+
                                                        '<font style="color:red; font-size: 24px; margin-left: 4px">*</font>'+
                                                    '</div>'+
                                                '</td>'+
											'</tr>'+
										'</table>'+
										'&emsp;&emsp;设备型号&emsp;&emsp;&emsp;<input readonly class="layui-input" id="deviceVersion" name="deviceVersion" lay-verify="deviceVersion" type="text" style="width:200px; margin-top:15px; display: inline;">'+
										'&emsp;&emsp;&emsp;&emsp;&emsp;使用地点&emsp;<input class="layui-input" id="useLocation" name="useLocation" lay-verify="useLocation" type="text" lay-verify="email" style="width:200px; display: inline;"><br>'+
										'&emsp;&emsp;设备出厂日期&emsp;<input readonly class="layui-input" id="outTime" name="outTime" lay-verify="outTime" type="text" style="width:200px; margin-top:15px; display: inline;">'+
										'&emsp;&emsp;&emsp;&emsp;&emsp;使用日期&emsp;<input class="layui-input" id="useTime" name="useTime" lay-verify="useTime" type="text" style="width:200px; display: inline;"><br>'+
										'&emsp;&emsp;设备生产厂家&emsp;<input readonly class="layui-input" id="manufacturers" name="manufacturers" lay-verify="manufacturers" type="text" style="width:558px; margin-top:15px; margin-bottom: 15px; display: inline;"><br>'+
									'</div>'+
									'&emsp;&emsp;<span style="margin-top: 30px;">附属设备明细</span>&emsp;<br>'+
									'<div style="border: 1px solid #E6E6E6; margin: 15px 15px;">'+
										'<table id="myTable1">'+
											'<thead>'+
												'<tr align="center">'+
													'<td><p style="margin-top: 10px;">名称</p></td>'+
													'<td><p style="margin-top: 10px;">规格型号</p></td>'+
													'<td><p style="margin-top: 10px;">性能参数</p></td>'+
													'<td><p style="margin-top: 10px;">数量</p></td>'+
													'<td><p style="margin-top: 10px;">单位</p></td>'+
													'<td><p style="margin-top: 10px;">操作</p></td>'+
												'</tr>'+
											'</thead>'+
											'<tbody id="tbody1">'+
												'<tr id="tr1" align="center" style="height: 52px">'+
                            						'<td><input class="layui-input" id="attachDeviceName1" name="attachDeviceName" lay-verify="attachDeviceName1" type="text" style="width:128px; margin-left: 5px; margin-top:5px; display: inline;"></td>'+
                            						'<td><input class="layui-input" id="attachDeviceVersion1" name="attachDeviceVersion" lay-verify="attachDeviceVersion1" type="text" style="width:128px; margin-left: 5px; margin-top:5px; display: inline;"></td>'+
                            						'<td><input class="layui-input" id="attachDeviceParam1" name="attachDeviceParam" lay-verify="attachDeviceParam1" type="text" style="width:128px; margin-left: 5px; margin-top:5px; display: inline;"></td>'+
                            						'<td><input class="layui-input" id="attachDeviceCount1" name="attachDeviceCount" lay-verify="attachDeviceCount1" type="text" style="width:128px; margin-left: 5px; margin-top:5px; display: inline;"></td>'+
                            						'<td><input class="layui-input" id="attachDeviceUnit1" name="attachDeviceUnit" lay-verify="attachDeviceUnit1" type="text" style="width:128px; margin-left: 5px; margin-top:5px; display: inline;"></td>'+
                            						'<td width="120px"><i class="layui-icon layui-icon-add-1" id="add1" style="font-size: 15px; color: #1E9FFF;"></i></td>'+
												'</tr>'+
											'</tbody>'+
										'</table>'+
									'</div>'+
									'&emsp;&emsp;<span style="margin-top: 30px;">检修</span>&emsp;<br>'+
									'<div style="border: 1px solid #E6E6E6; margin: 15px 15px;">'+
										'<table id="myTable">'+
											'<thead>'+
												'<tr align="center">'+
													'<td width="200px"><p style="margin-top: 10px; margin-bottom: 10px">检修周期</p></td>'+
													'<td width="160px"><p style="margin-top: 10px; margin-bottom: 10px">大修</p></td>'+
													'<td width="160px"><p style="margin-top: 10px; margin-bottom: 10px">中修</p></td>'+
													'<td width="160px"><p style="margin-top: 10px; margin-bottom: 10px">小修</p></td>'+
													'<td width="50px"><p style="margin-top: 10px; margin-bottom: 10px">操作</p></td>'+
												'</tr>'+
											'</thead>'+
											'<tbody id="tbody">'+
												'<tr id="tr1" align="center" style="height: 52px">'+
													'<td><input class="layui-input" id="overhaulCycle" name="overhaulCycle" lay-verify="overhaulCycle" type="text" style="margin-left: 10px; width: 150px"></td>'+
													'<td>'+
														'<p style="">' +
															'<select name="bigOverhaul">'+
																'<option value=""></option>'+
																'<option value="大修">大修</option>' +
															'</select>' +
														'</p>' +
													'</td>'+
													'<td>'+
														'<p style="margin-left: 15px">' +
															'<select name="midOverhaul" >'+
																'<option value=""></option>'+
																'<option value="中修">中修</option>' +
															'</select>' +
														'</p>' +
													'</td>'+
													'<td>'+
														'<p style="margin-left: 15px">' +
															'<select name="smallOverhaul">'+
																'<option value=""></option>'+
																'<option value="小修">小修</option>' +
															'</select>' +
														'</p>' +
													'</td>'+
													'<td><i class="layui-icon layui-icon-add-1" id="add" style="font-size: 15px; color: #1E9FFF;"></i><!--<br><i class="layui-icon layui-icon-close" id="recover" style="font-size: 15px; color: #1E9FFF; font-weight: bold;"></i>--></td>'+
												'</tr>'+
											'</tbody>'+
										'</table>'+
									'</div>'+
									'&emsp;&emsp;<span style="margin-top: 30px;">易耗品</span>&emsp;<br>'+
									'<div style="border: 1px solid #E6E6E6; margin: 15px 15px;">'+
										'<table id="myTable2">'+
											'<thead>'+
												'<tr align="center">'+
													'<td><p style="margin-top: 10px; margin-left: 11px">易耗品名称</p></td>'+
													'<td><p style="margin-top: 10px; margin-left: 11px">规格型号</p></td>'+
													'<td><p style="margin-top: 10px; margin-left: 6px">数量</p></td>'+
													'<td><p style="margin-top: 10px; margin-left: 2px">备注</p></td>'+
													'<td><p style="margin-top: 10px; margin-left: 5px">单位</p></td>'+
													'<td><p style="margin-top: 10px; margin-left: 5px">操作</p></td>'+
												'</tr>'+
											'</thead>'+
											'<tbody id="tbody2">'+
												'<tr id="tr1" align="center" style="height: 52px">'+
													'<td><input class="layui-input" id="lubricateOilName1" name="lubricateOilName" lay-verify="lubricateOilName" type="text" style="width:120px; margin-left: 10px; margin-top:5px; display: inline;"></td>'+
													'<td><input class="layui-input" id="lubricateVersion1" name="lubricateVersion" lay-verify="lubricateVersion" type="text" style="width:120px; margin-left: 10px; margin-top:5px; display: inline;"></td>'+
													'<td><input class="layui-input" id="lubricateML1" name="lubricateML" lay-verify="lubricateML" type="text" style="width:120px; margin-left: 10px; margin-top:5px; display: inline;"></td>'+
													'<td><input class="layui-input" id="lubricateRemark1" name="lubricateRemark" lay-verify="lubricateRemark" type="text" style="width:120px; margin-left: 10px; margin-top:5px; display: inline;"></td>'+
													'<td><input class="layui-input" id="remark011" name="remark01" lay-verify="remark01" type="text" style="width:120px; margin-left: 10px; margin-top:5px; display: inline;"><br></td>'+
													'<td width="120px"><i class="layui-icon layui-icon-add-1" id="add2" style="font-size: 15px; color: #1E9FFF;"></i></td>'+
												'</tr>'+
											'</tbody>'+
										'</table>'+
									'</div>'+
									'<button class="layui-btn layui-btn-blue" id="subBtn" lay-submit lay-filter="addForm" style="margin-left:250px; margin-top: 25px; margin-bottom: 25px">提交</button>'+
									'&emsp;&emsp;&emsp;&emsp;<button type="reset" class="layui-btn layui-btn-primary">重置</button>'+
                            	'</form>'
                        ,success: function(){
                            //设备出厂日期
                            laydate.render({
                                elem: '#outTime'
                            });
                            //使用日期
                            laydate.render({
                                elem: '#useTime'
                            });

                            $.ajax({
                                type: 'POST',
                                url: '${pageContext.request.contextPath}/device/queryAllDeviceList.do',
                                dataType: 'json',
                                async: false,
                                success: function (data){
                                    for (var i = 0; i < data.length; i++) {
                                        $("#deviceNo").append("<option value='"+ data[i].deviceNo +"'>"+ data[i].deviceNo +"</option>");
                                    }
                                }
                            });
                            form.render();
                        }
                    });
                    break;
                //批量删除
                case 'delete':
                    var data = checkStatus.data;
                    var idArr = new Array();
                    if(data.length==0){
                        toastr.warning("请至少选择一条记录！");
                    }
                    for(var i=0;i<data.length;i++){
                        idArr[i] = data[i].id;
                    }
                    $.ajax({
                        type:'post',
                        url:'${pageContext.request.contextPath }/deviceFile/deleteDeviceFileById.do',
                        data:{"idArr" : idArr},
                        success:function(data){
                            layer.confirm('确定删除吗？', function(index){
                                if(data > 0){
                                    toastrStyle();
                                    toastr.success("删除成功！");
                                    setTimeout(function(){
                                        location.reload();
                                    },1000);
                                }else{
                                    toastrStyle();
                                    toastr.warning("删除失败！");
                                    setTimeout(function(){
                                        location.reload();
                                    },1000);
                                }
                            });
                        }
                    });
                break;
            };
        });

        //监听行工具事件
        table.on('tool(tableList)', function(obj){
            var data = obj.data;
            var idArr = new Array();
            //单个删除
            if(obj.event === 'del'){
                layer.confirm('确定删除吗？', function(index){
                    var id = obj.data.id;
                    idArr[0] = id;
                    $.ajax({
                        type:'post',
                        url:'${pageContext.request.contextPath }/deviceFile/deleteDeviceFileById.do',
                        data:{ "idArr" : idArr },
                        success:function(data){
                            if(data > 0){
                                toastrStyle();
                                toastr.success("删除成功！");
                                setTimeout(function(){
                                    location.reload();
                                },1000);
                            }else{
                                toastrStyle();
                                toastr.warning("删除失败！");
                                setTimeout(function(){
                                    location.reload();
                                },1000);
                            }
                        }
                    })
                    layer.close(index);
                });
            } else if(obj.event === 'edit'){
                $("#deviceNo1").find("option").not(":first").remove();
                layer.open({
                    type: 1 					//Page层类型
                    ,area: ['630px', '420px'] 		//宽  高
                    ,title: '编辑'
                    ,shade: 0.6 				//遮罩透明度
                    ,maxmin: true 				//允许全屏最小化
                    ,anim: 1 					//0-6的动画形式，-1不开启
					,content: '<div id="editDivID">' +
								'<form class="layui-form" id="editFormID">' +
									'<table>' +
										'<tr>' +
											'<td><input class="layui-hide" id="id" name="id" value="'+data.id+'"></td>' +
										'</tr>' +
										'<tr>' +
											'<td><label class="layui-form-label left-label" style="margin-top:20px">设备编号</label></td>' +
											'<td>' +

												'<div style="">'+
													'<div style="width: 150px; margin-left: 0px; margin-top:20px; float: left">' +
														'<select disabled class="layui-select" id="deviceNo1" name="deviceNo" lay-filter="displayInfo" lay-verify="deviceNo">' +
															'<option value="">请选择</option>' +
														'</select>' +
													'</div>' +
                                                    '<div style="margin-top: 29px; float: left">'+
                                                        '<font style="color:red; font-size: 24px; margin-left: 4px">*</font>'+
                                                    '</div>'+
												'</div>' +
											'</td>' +
											'<td><label class="layui-form-label left-label" style="margin-top:20px">设备名称</label></td>' +
											'<td><input readonly class="layui-input" id="deviceName1" name="deviceName" value="'+data.deviceName+'" lay-verify="deviceName" style="width:150px; margin-top:20px; display:inline;">' +
                                                '<div class="layui-inline" style="margin-top: 4px;">'+
                                                    '<font style="color:red; font-size: 24px; margin-left: 4px">*</font>'+
                                                '</div>'+
                                            '</td>' +
										'</tr>' +
										'<tr style="height:20px"></tr>' +
										'<tr>' +
											'<td><label class="layui-form-label left-label">设备型号</label></td>' +
											'<td><input readonly class="layui-input" id="deviceVersion1" name="deviceVersion" value="'+data.deviceVersion+'" lay-verify="deviceVersion" style="width:150px"></td>' +
											'<td><label class="layui-form-label left-label">使用地点</label></td>' +
											'<td><input class="layui-input" id="useLocation1" name="useLocation" value="'+data.useLocation+'" lay-verify="useLocation" style="width:150px"></td>' +
										'</tr>' +
										'<tr style="height:20px"></tr>' +
										'<tr>' +
											'<td><label class="layui-form-label left-label">出厂日期</label></td>' +
											'<td><input readonly class="layui-input" id="outTime1" name="outTime" value="'+data.outTime+'" lay-verify="outTime" style="width:150px"></td>' +
											'<td><label class="layui-form-label left-label">使用日期</label></td>' +
											'<td><input class="layui-input" id="useTime1" name="useTime" value="'+data.useTime+'" lay-verify="useTime" style="width:150px"></td>' +
										'</tr>' +
										'<tr style="height:20px"></tr>' +
										'<tr>' +
											'<td><label class="layui-form-label left-label">设备生产厂家</label></td>' +
											'<td><input readonly class="layui-input" id="manufacturers1" name="manufacturers" value="'+data.manufacturers+'" lay-verify="manufacturers" style="width:150px"></td>' +
											'<td></td>' +
											'<td></td>' +
										'</tr>' +
										'<tr style="height:20px"></tr>' +
										'<tr>' +
											'<td colspan="2"><button class="layui-btn layui-btn-blue" lay-submit lay-filter="editForm" style="margin-left:160px; margin-bottom: 20px">提交</button></td>' +
											'<td colspan="2">&emsp;&emsp;&emsp;&emsp;<button type="reset" class="layui-btn layui-btn-primary" style="margin-bottom: 20px">重置</button></td>' +
										'</tr>' +
									'</table>' +
								'</form>' +
							'</div>'
                    ,success: function(){
                        //出厂日期
                        laydate.render({
                            elem: '#outTime1'
                        });
                        //使用日期
                        laydate.render({
                            elem: '#useTime1'
                        });
                        //下拉框查找所有设备
                        $.ajax({
                            type: 'POST',
                            url: '${pageContext.request.contextPath}/device/queryAllDeviceList.do',
                            dataType: 'json',
                            async: false,
                            success: function (datas){
                                for (var i = 0; i < datas.length; i++) {
                                    $("#deviceNo1").append("<option value='"+ datas[i].deviceNo +"'>"+ datas[i].deviceNo +"</option>");
                                    if(datas[i].deviceNo == data.deviceNo){
                                        $("#deviceNo1").val(data.deviceNo);
                                    }
                                }
                            }
                        });
                        form.render();
                    }
                });
            }
        });

        /**
         * 通用表单提交(AJAX方式)(新增)
         */
        form.on('submit(addForm)', function (data) {
            $("#subBtn").attr("disabled",true);
            $.ajax({
                url : '${pageContext.request.contextPath}/deviceFile/addDeviceFile.do',
                data: $("#addFormID").serialize(),
                cache : false,
                type : "post",
            }).done(
                function(res) {
                    if (res > 0) {
                        /*检修循环*/
                        $("#tbody tr").each(function(i,dom){
                            var tr = $(dom).closest("tr");
                            var tds = tr.find("td");
                            //主表插入行ID
                            var dId = res;
                            var overhaulCycle = tds[0].getElementsByTagName("input")[0].value;
                            var bigOverhaul = tds[1].getElementsByTagName("select")[0].value;
                            var midOverhaul = tds[2].getElementsByTagName("select")[0].value;
                            var smallOverhaul = tds[3].getElementsByTagName("select")[0].value;
                            $.ajax({
                                type:'post'
                                ,url:'${pageContext.request.contextPath}/deviceFile/addDeviceFileOverhaul.do'
                                ,data:{dId:dId,overhaulCycle:overhaulCycle,bigOverhaul:bigOverhaul,midOverhaul:midOverhaul,smallOverhaul:smallOverhaul}
                                ,dataType:'json'
								,async: false
                                ,success:function(data){
                                    console.log("检修记录成功");
                                }
                            })
                        });

                        /*附属设备明细循环*/
                        $("#tbody1 tr").each(function(i,dom){
                            var tr = $(dom).closest("tr");
                            var tds = tr.find("td");
                            //主表插入行ID
                            var dId = res;
                            var attachDeviceName = tds[0].getElementsByTagName("input")[0].value;
                            var attachDeviceVersion = tds[1].getElementsByTagName("input")[0].value;
                            var attachDeviceParam = tds[2].getElementsByTagName("input")[0].value;
                            var attachDeviceCount = tds[3].getElementsByTagName("input")[0].value;
                            var attachDeviceUnit = tds[4].getElementsByTagName("input")[0].value;
                            $.ajax({
                                type:'post'
                                ,url:'${pageContext.request.contextPath}/deviceFile/addDeviceFileAttach.do'
                                ,data:{dId:dId,attachDeviceName:attachDeviceName,attachDeviceVersion:attachDeviceVersion,attachDeviceParam:attachDeviceParam,attachDeviceCount:attachDeviceCount, attachDeviceUnit:attachDeviceUnit}
                                ,dataType:'json'
                                ,async: false
                                ,success:function(data){
                                    console.log("附属设备明细记录成功");
                                }
                            })
                        });

                        /*易耗品循环*/
                        $("#tbody2 tr").each(function(i,dom){
                            var tr = $(dom).closest("tr");
                            var tds = tr.find("td");
                            //主表插入行ID
                            var dId = res;
                            var lubricateOilName = tds[0].getElementsByTagName("input")[0].value;
                            var lubricateVersion = tds[1].getElementsByTagName("input")[0].value;
                            var lubricateML = tds[2].getElementsByTagName("input")[0].value;
                            var lubricateRemark = tds[3].getElementsByTagName("input")[0].value;
                            var remark01 = tds[4].getElementsByTagName("input")[0].value;
                            $.ajax({
                                type:'post'
                                ,url:'${pageContext.request.contextPath}/deviceFile/addDeviceFileLubricate.do'
                                ,data:{dId:dId,lubricateOilName:lubricateOilName,lubricateVersion:lubricateVersion,lubricateML:lubricateML,lubricateRemark:lubricateRemark, remark01:remark01}
                                ,dataType:'json'
                                ,async: false
                                ,success:function(data){
                                    console.log("易耗品记录成功");
                                }
                            })
                        });
                        /*————————————*/
                        toastrStyle();
                        toastr.success('新增成功！');
                        setTimeout(function(){
                            location.reload();
                        },1000);
                    }
                }
            ).fail(
                function(res) {
                    toastrStyle();
                    toastr.error('新增失败！');
                    setTimeout(function(){
                        location.reload();
                    },1000);
                }
            )
            return false;
        });
        /**
         * 通用表单提交(AJAX方式)(修改)
         */
        form.on('submit(editForm)', function (data) {
            $("#deviceNo1").removeAttr("disabled");
            $.ajax({
                url : '${pageContext.request.contextPath}/deviceFile/editDeviceFileById.do',
                data: $("#editFormID").serialize(),
                cache : false,
                type : "post",
            }).done(
                function(res) {
                    if (res > 0) {
                        toastrStyle();
                        toastr.success('修改成功！');
                        setTimeout(function(){
                            location.reload();
                        },1000);
                    }
                }
            ).fail(
                function(res) {
                    toastrStyle();
                    toastr.error('修改失败！');
                    setTimeout(function(){
                        location.reload();
                    },1000);
                }
            )
            return false;
        });

        /**
         * 新增表单校验
         */
        form.verify({
            //value：表单的值item：表单的DOM对象
            deviceName: function(value, item){
                if(value == ''){
                    return '设备名称不能为空';
                }
            },
            deviceNo: function(value, item){
                if(value == ''){
                    return '设备编号不能为空';
                }
            }
        });

        form.on('select(displayInfo)', function(data){
            $.ajax({
                type: 'POST',
                url: '${pageContext.request.contextPath}/device/queryDeviceInfoByNo.do',
                data: {deviceNo:$('#deviceNo').val()},
                /* dataType: 'json', */
                /* async: false, */
                success: function (data){
                    var device = eval('(' +data+ ')');
                    $('#deviceName').val(device.deviceName);
                    $('#deviceVersion').val(device.deviceVersion);
                    $('#manufacturers').val(device.manufacturers);
                    $('#outTime').val(device.outTime);
                }
            });
        });
    });
    toastr.options.positionClass = 'toast-top-center'; //提示框的位置设置为中上
    //提示框样式
    function toastrStyle(){
        toastr.options = {
            "closeButton": false,
            "debug": false,
            "newestOnTop": false,
            "progressBar": false,
            "positionClass": "toast-top-center",
            "preventDuplicates": false,
            "onclick": null,
            "showDuration": "5000",
            "hideDuration": "1000",
            "timeOut&quot": "100000",
            "extendedTimeOut": "0",
            "showEasing": "swing",
            "hideEasing": "linear",
            "showMethod": "fadeIn",
            "hideMethod": "fadeOut"
        };
    }

    //点击"+"和"-"效果
    $(function(){
        /* $("#add").click(function(){ */
        $("body").on("click", "#add", function() {
            var index;
            var rowId = $(this).parents('tr').attr("id");
            var tbody = document.getElementById("tbody");
            index = tbody.rows.length + 1;
            $("#rowCount").val(index);
            var tab = document.getElementById('myTable');
            //指定行号
            var rowNumNext = document.getElementById(rowId).rowIndex + 1;
            //在指定行下插入一行
            var tr = tab.insertRow(rowNumNext);
            //给tr设置动态Id和样式
            tr.id = "tr" + index;
            tr.style = "text-align: center; height: 52px";
            //在行下插入列内容
            var cell0 = tr.insertCell(0);
            var cell1 = tr.insertCell(1);
            var cell2 = tr.insertCell(2);
            var cell3 = tr.insertCell(3);
            var cell4 = tr.insertCell(4);

            cell0.innerHTML = '<td><input class="layui-input" id="overhaulCycle" name="overhaulCycle" type="text" style="margin-left: 28px; width: 150px"></td>';
            cell1.innerHTML = '<td>'+
					'<p style="width: 160px">'+
						'<select name="bigOverhaul">'+
							'<option value=""></option>'+
							'<option value="大修">大修</option>'+
						'</select>' +
					'</p>'+
                '</td>';
            cell2.innerHTML = '<td>'+
					'<p style="margin-left: 15px">'+
						'<select name="midOverhaul">'+
							'<option value=""></option>'+
							'<option value="中修">中修</option>'+
						'</select>' +
					'</p>'+
                '</td>';
            cell3.innerHTML = '<td>'+
					'<p style="margin-left: 15px">'+
						'<select name="smallOverhaul">'+
							'<option value=""></option>'+
							'<option value="小修">小修</option>'+
						'</select>' +
					'</p>'+
                '</td>';
            cell4.innerHTML = '<td><i class="layui-icon layui-icon-add-1" id="add" style="font-size: 15px; color: #1E9FFF;"></i><br><i class="layui-icon layui-icon-close" id="recover" style="font-size: 15px; color: #1E9FFF; font-weight: bold;"></i></td>';

            layui.use('form', function(){
                    var form = layui.form;
                    form.render('select');
                }
            );
        });

        $("body").on("click", "#recover", function() {
            var rowId = $(this).parents('tr').attr("id");
            $("#"+rowId).remove();
        })

        /*附属设备明细*/
        $("body").on("click", "#add1", function() {
            var index;
            var rowId = $(this).parents('tr').attr("id");
            var tbody = document.getElementById("tbody1");
            index = tbody.rows.length + 1;
            $("#rowCount").val(index);
            var tab = document.getElementById('myTable1');
            //指定行号
            var rowNumNext = document.getElementById(rowId).rowIndex + 1;
            //在指定行下插入一行
            var tr = tab.insertRow(rowNumNext);
            //给tr设置动态Id和样式
            tr.id = "tr" + index;
            tr.style = "text-align: center; height: 52px";
            //在行下插入列内容
            var cell0 = tr.insertCell(0);
            var cell1 = tr.insertCell(1);
            var cell2 = tr.insertCell(2);
            var cell3 = tr.insertCell(3);
            var cell4 = tr.insertCell(4);
            var cell5 = tr.insertCell(5);

            cell0.innerHTML = '<td><input class="layui-input" id="attachDeviceName1" name="attachDeviceName" lay-verify="attachDeviceName1" type="text" style="width:128px; margin-left: 5px; margin-top:5px; display: inline;"></td>';
            cell1.innerHTML = '<td><input class="layui-input" id="attachDeviceVersion1" name="attachDeviceVersion" lay-verify="attachDeviceVersion1" type="text" style="width:128px; margin-left: 5px; margin-top:5px; display: inline;"></td>';
            cell2.innerHTML = '<td><input class="layui-input" id="attachDeviceParam1" name="attachDeviceParam" lay-verify="attachDeviceParam1" type="text" style="width:128px; margin-left: 5px; margin-top:5px; display: inline;"></td>';
            cell3.innerHTML = '<td><input class="layui-input" id="attachDeviceCount1" name="attachDeviceCount" lay-verify="attachDeviceCount1" type="text" style="width:128px; margin-left: 5px; margin-top:5px; display: inline;"></td>';
            cell4.innerHTML = '<td><input class="layui-input" id="attachDeviceUnit1" name="attachDeviceUnit" lay-verify="attachDeviceUnit1" type="text" style="width:128px; margin-left: 5px; margin-top:5px; display: inline;"></td>';
            cell5.innerHTML = '<td width="120px"><i class="layui-icon layui-icon-add-1" id="add1" style="font-size: 15px; color: #1E9FFF;"></i><br><i class="layui-icon layui-icon-close" id="recover1" style="font-size: 15px; color: #1E9FFF; font-weight: bold;"></i></td>';
        });

        $("body").on("click", "#recover1", function() {
            var rowId = $(this).parents('tr').attr("id");
            $("#"+rowId).remove();
        })

        /*易耗品明细*/
        $("body").on("click", "#add2", function() {
            var index;
            var rowId = $(this).parents('tr').attr("id");
            var tbody = document.getElementById("tbody2");
            index = tbody.rows.length + 1;
            $("#rowCount").val(index);
            var tab = document.getElementById('myTable2');
            //指定行号
            var rowNumNext = document.getElementById(rowId).rowIndex + 1;
            //在指定行下插入一行
            var tr = tab.insertRow(rowNumNext);
            //给tr设置动态Id和样式
            tr.id = "tr" + index;
            tr.style = "text-align: center; height: 52px";
            //在行下插入列内容
            var cell0 = tr.insertCell(0);
            var cell1 = tr.insertCell(1);
            var cell2 = tr.insertCell(2);
            var cell3 = tr.insertCell(3);
            var cell4 = tr.insertCell(4);
            var cell5 = tr.insertCell(5);

            cell0.innerHTML = '<td><input class="layui-input" id="lubricateOilName1" name="lubricateOilName" lay-verify="lubricateOilName" type="text" style="width:120px; margin-left: 10px; margin-top:5px; display: inline;"></td>';
            cell1.innerHTML = '<td><input class="layui-input" id="lubricateVersion1" name="lubricateVersion" lay-verify="lubricateVersion" type="text" style="width:120px; margin-left: 10px; margin-top:5px; display: inline;"></td>';
            cell2.innerHTML = '<td><input class="layui-input" id="lubricateML1" name="lubricateML" lay-verify="lubricateML" type="text" style="width:120px; margin-left: 10px; margin-top:5px; display: inline;"></td>';
            cell3.innerHTML = '<td><input class="layui-input" id="lubricateRemark1" name="lubricateRemark" lay-verify="lubricateRemark" type="text" style="width:120px; margin-left: 10px; margin-top:5px; display: inline;"></td>';
            cell4.innerHTML = '<td><input class="layui-input" id="remark011" name="remark01" lay-verify="remark01" type="text" style="width:120px; margin-left: 10px; margin-top:5px; display: inline;"><br></td>';
            cell5.innerHTML = '<td width="120px"><i class="layui-icon layui-icon-add-1" id="add2" style="font-size: 15px; color: #1E9FFF;"></i><br><i class="layui-icon layui-icon-close" id="recover2" style="font-size: 15px; color: #1E9FFF; font-weight: bold;"></i></td>';
        });

        $("body").on("click", "#recover2", function() {
            var rowId = $(this).parents('tr').attr("id");
            $("#"+rowId).remove();
        })
    });

    //附属设备明细
    function attachDeviceEvent(dId){
        layer.open({
            type: 1 					//Page层类型
            ,area: ['500px', '450px']   //宽  高
            ,title: '附属设备明细'
            ,shade: 0.6 				//遮罩透明度
            ,maxmin: true 			    //允许全屏最小化
            ,anim: 1 					//0-6的动画形式，-1不开启
            /* ,content: $("#lookupTable2") */
            ,content: '<table class="layui-hide" id="lookupTable1" lay-filter="lookupTable1"></table>'
            ,success: function(){
                layui.use(['table'], function(){
                    var table = layui.table;
                    table.render({
                        elem: '#lookupTable1'
                        ,url:'${pageContext.request.contextPath }/deviceFile/queryAttachDetailById.do?dId='+dId
                        ,title: '附属设备明细'
                        ,limits:[10,20,30]
                        ,cols: [[
                            /*{type: 'checkbox', fixed: 'left'},*/
                            {field:'id', title:'ID', fixed: 'left', unresize: true, sort: true, type:'numbers'},
                            {field:'attachDeviceName', title:'附属设备名称'},
                            {field:'attachDeviceVersion', title:'附属设备规格型号'},
                            {field:'attachDeviceParam', title:'附属设备性能参数'},
                            {field:'attachDeviceCount', title:'附属设备数量'},
                            {field:'attachDeviceUnit', title:'附属设备单位'}
                        ]]
                        ,page: false
                    });
                });
            }
        });
    }

    //检修
    function overhaulEvent(dId){
        layer.open({
            type: 1 					//Page层类型
            ,area: ['500px', '450px']   //宽  高
            ,title: '检修'
            ,shade: 0.6 				//遮罩透明度
            ,maxmin: true 			    //允许全屏最小化
            ,anim: 1 					//0-6的动画形式，-1不开启
            ,content: '<table class="layui-hide" id="lookupTable1" lay-filter="lookupTable1"></table>'
            ,success: function(){
                layui.use(['table'], function(){
                    var table = layui.table;
                    table.render({
                        elem: '#lookupTable1'
                        ,url:'${pageContext.request.contextPath }/deviceFile/queryDeviceFileOverhaulById.do?dId='+dId
                        ,title: '检修'
                        ,limits:[10,20,30]
                        ,cols: [[
                            /*{type: 'checkbox', fixed: 'left'},*/
                            {field:'id', title:'ID', fixed: 'left', unresize: true, sort: true, type:'numbers'},
                            {field:'overhaulCycle', title:'检修周期'},
                            {field:'bigOverhaul', title:'大修'},
                            {field:'midOverhaul', title:'中修'},
                            {field:'smallOverhaul', title:'小修'}
                        ]]
                        ,page: false
                    });
                });
            }
        });
    }

    //易耗品
    function lubricateEvent(dId){
        layer.open({
            type: 1 					//Page层类型
            ,area: ['500px', '450px']   //宽  高
            ,title: '易耗品'
            ,shade: 0.6 				//遮罩透明度
            ,maxmin: true 			    //允许全屏最小化
            ,anim: 1 					//0-6的动画形式，-1不开启
            ,content: '<table class="layui-hide" id="lookupTable1" lay-filter="lookupTable1"></table>'
            ,success: function(){
                layui.use(['table'], function(){
                    var table = layui.table;
                    table.render({
                        elem: '#lookupTable1'
                        ,url:'${pageContext.request.contextPath }/deviceFile/queryDeviceFileLubricateById.do?dId='+dId
                        ,title: '易耗品'
                        ,limits:[10,20,30]
                        ,cols: [[
                            /*{type: 'checkbox', fixed: 'left'},*/
                            {field:'id', title:'ID', fixed: 'left', unresize: true, sort: true, type:'numbers'},
                            {field:'lubricateOilName', title:'易耗品名称'},
                            {field:'lubricateVersion', title:'规格型号'},
                            {field:'lubricateML', title:'数量'},
                            {field:'lubricateRemark', title:'备注'},
                            {field:'remark01', title:'单位'}
                        ]]
                        ,page: false
                    });
                });
            }
        });
    }

    //根据申请表ID查询保养详细
    function maintenanceRecordDetailEvent(mId){
        layer.open({
            type: 1 					//Page层类型
            ,area: ['500px', '450px']   //宽  高
            ,title: '保养项目明细'
            ,shade: 0.6 				//遮罩透明度
            ,maxmin: true 			    //允许全屏最小化
            ,anim: 1 					//0-6的动画形式，-1不开启
            /* ,content: $("#lookupTable2") */
            ,content: '<table class="layui-hide" id="lookupTable1" lay-filter="lookupTable1"></table>'
            ,success: function(){
                layui.use(['table'], function(){
                    var table = layui.table;
                    table.render({
                        elem: '#lookupTable1'
                        ,url:'${pageContext.request.contextPath }/maintResume/queryMaintenanceRecordDetailById.do?mId='+mId
                        ,title: '保养项目明细'
                        ,limits:[10,20,30]
                        ,cols: [[
                            /*{type: 'checkbox', fixed: 'left'},*/
                            {field:'id', title:'ID', fixed: 'left', unresize: true, sort: true, type:'numbers'},
                            {field:'maintainItem', title:'保养项目'},
                            {field:'remark', title:'结果'},
                            {field:'result', title:'备注'}
                        ]]
                        ,page: false
                    });
                });
            }
        });
    }

    //日期格式转换1
    function createTime(v){
        var date = new Date(v);
        var y = date.getFullYear();
        var M = date.getMonth()+1;
        M = M<10?'0'+M:M;
        var d = date.getDate();
        d = d<10?("0"+d):d;
        var h = date.getHours();
        h = h<10?("0"+h):h;
        var m = date.getMinutes();
        m = m<10?("0"+m):m;
        var str = y+"-"+M+"-"+d+" "+h+":"+m;
        return str;
    }
</script>

</body>
</html>